package com.zl_huang.example.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.zl_huang.example.model.ExamTestType;
@Repository
public class ExamTestTypeDaoHibernateImpl extends BaseHibernateDAO<ExamTestType> implements IExamTestTypeDaoHibernate {
	@Autowired
	private SessionFactory sessionFactory;
	@Transactional
	public Session getSession(){
		return this.sessionFactory.getCurrentSession();
	}

	@Override
	@Transactional
	public List<ExamTestType> findAllExamTestTypet() throws Exception {
		Session session = getSession();
		String hql = "from ExamTestType";
		@SuppressWarnings("unchecked")
		List<ExamTestType> examTestTypeList = session.createQuery(hql).list();
		return examTestTypeList;
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional
	public ExamTestType getExamTestTypeById(Integer id) throws Exception {
		Session session = getSession();
		String hql = "from ExamTestType examTestType where examTestType.id=" + id;
		List<ExamTestType> examTestTypeList = session.createQuery(hql).list();
		if(!examTestTypeList.isEmpty()){
			return examTestTypeList.get(0);
		}else{
			return null;
		}
		
	}

}
